package com.zhiyou100.crowd.Controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhiyou100.crowd.Iservice.UserIservice;
import com.zhiyou100.crowd.pojo.TbUser;

@Controller
@RequestMapping("Users")
public class UserController {
	@Resource(name="userIservice")
	private UserIservice userIservice;
	private HttpServletRequest request;

	@ModelAttribute
	public void getrequest(HttpServletRequest request) {
		this.request=request;
	}
	
	@RequestMapping("add.do")
	@ResponseBody
	public String add(TbUser tbUser) {
		Integer flag=userIservice.add(tbUser);
		if(flag==1) {
			return "1";
		}else {
			return "2";
		}
	}
	
	@RequestMapping("yz.do")
	@ResponseBody
	public String yz(TbUser tbUser) {
		List<TbUser> list=userIservice.yz(tbUser);
		if(list.size()>0) {
			request.getSession().setAttribute("users", list.get(0));
			return "1";
		}else {
			return "2";
		}
	}
	
	@RequestMapping("quit.do")
	public String pd() {
		request.getSession().removeAttribute("users");
		return "index";
	}
	
}
